package com.cike.ssm.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cike.ssm.utils.baidu.TransApi;

public class TransUtil {
	private static final String APP_ID = "";
	private static final String SECURITY_KEY = "";

	/**
	 * 中文翻译英文
	 * 
	 * @param query
	 * @return
	 */
	public static String trans(String query) {
		TransApi api = new TransApi(APP_ID, SECURITY_KEY);
		String json = api.getTransResult(query, "auto", "en");
		JSONObject jsonObject = JSON.parseObject(json);
		Object obj = jsonObject.get("trans_result");
		JSONArray jsonArray = JSONArray.parseArray(obj.toString());
		String dst = JSON.parseObject(jsonArray.get(0).toString()).get("dst").toString();
		return dst;
	}
}
